import java.io.File;
import java.io.StringReader;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Locale;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.InputSource;


public class ReportCreatorBK {
	static DocumentBuilderFactory docFactory;
	static DocumentBuilder docBuilder;
	static Document doc;
	static Element body;
	static NumberFormat formatter;
	
	static double pageWidthInCM = 15.90;
	
	
	
	public static void run(){
		System.out.println("Beginning");
		try {
			init();
			
			//create stuff you want
			
			
			
			
			//Creating header
			createHeaderAndFooter();
			
			
			//Generating depencies
			
			
			
			
			
			
			
			save();
		} catch (ParserConfigurationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (TransformerException e){
			e.printStackTrace();
		}
	}
	
	private static void init() throws ParserConfigurationException{
		docFactory = DocumentBuilderFactory.newInstance();
		docBuilder = docFactory.newDocumentBuilder();
 
		// root elements
		doc = docBuilder.newDocument();
		Element rootElement = doc.createElement("Report");
		rootElement.setAttribute("xmlns", "http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition");
		rootElement.setAttribute("xmlns:rd", "http://schemas.microsoft.com/SQLServer/reporting/reportdesigner");
		doc.appendChild(rootElement);
		
		body = doc.createElement("Body");
		
		rootElement.appendChild(body);
		
		//NumberFormat formatter = new DecimalFormat("#0.00");
		formatter = NumberFormat.getInstance(Locale.US);
		formatter.setMinimumFractionDigits(2);
		
		Element width = doc.createElement("Width");
		width.setTextContent(formatter.format(pageWidthInCM) + "cm");
		rootElement.appendChild(width);
	}
	
	private static void createHeaderAndFooter(){
		Element page = doc.createElement("Page");
		
		
		
		
		
		
		
		
		
		
		
	}
	
	private static void createTitle(){
		
	}

	private static void createDualRow(){
		
	}
	
	private static void createSingleRow(){
		
	}
	
	private static void save() throws TransformerException{
		// write the content into xml file
		TransformerFactory transformerFactory = TransformerFactory.newInstance();
		Transformer transformer = transformerFactory.newTransformer();
		DOMSource source = new DOMSource(doc);
		//StreamResult result = new StreamResult(new File("C:\\file.xml"));
 
		// Output to console for testing
		StreamResult result = new StreamResult(System.out);
 
		transformer.transform(source, result);
 
		System.out.println("File saved!");
	
	}
}
